﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Reflection;
using XiaoMan.Model.Models;

namespace XiaoMan.Factory
{
    public class SessionFactory
    {
        public static T CreatDAO<T>()
        {
            string DllName = ConfigurationManager.AppSettings["DllName"];
            Assembly assembly = Assembly.Load(DllName);
            Type[] types = assembly.GetTypes();
            Type target = null;
            foreach (var t in types)
            {
                if (typeof(T).IsAssignableFrom(t))
                {
                    target = t;
                    break;
                }
            }
            T dao = default(T);
            if (target != null)
            {
                dao = (T)Activator.CreateInstance(target);
            }
            return dao;
        }
        public static int Save()
        {
            return DbContextFactory.GetDbContext().SaveChanges();
        }
    }
}
